'''
Coron Lattice Drawer
Author: Victor Codocedo H.
Universintentd Tecnica Federico Santa Maria

Usage:
python coron_drawer.py lats/baclat.lat

baclat.lat is the output of LECO from Coron.
Add names, extension and stability options when executing LECO.
LECO is provided on Coron
'''
from vtk import *
import matplotlib
from pylab import *
from numpy import mean
import sys
from utility_functions import *
from lattice_functions import *

'''
#####################################################
######## MAIN CODE ##################################
#####################################################
'''
staboffset=0
doClean = True
lattice = ""
colors = ['r','g','b','y']
markers = ['s','o','^','*']
labels = ["a=0.45","a=0.47","original"]
if len(sys.argv)<2:
	print "\n*** usage:",sys.argv[0]," [latfile] [stability offset (default=0)]"
	exit()
else:
	path = sys.argv[1]
if len(sys.argv) > 2:
	staboffset = float(sys.argv[2])

files = get_files_on_path(path)
fig = plt.figure(figsize=[9,9])
ax1 = fig.add_subplot(111)
i = 0
for lattice in files:
	reale, reallev, realmaxlev, realat, realden, realtime = readLattice(path+lattice)
	stabs = []
	for e in reale:
		stabs.append(reale[e]["stability"])
	stabs.sort()
	# Stability Distribution 
	h,bins=matplotlib.numpy.histogram(stabs, bins=10,normed=True)
	ax1.plot(bins[1:],h,'s',ls='--',marker=markers[i],color=colors[i],label=labels[i])
	xlabel("Stability")
	ylabel("hits")
	i += 1
ax1.grid(True)
ax1.legend(loc="best")
savefig("figura.eps")
plt.show()

'''
# Attributes cardinality v/s Stability 
x = []
y = []
for i in stabs:
	x.append(len(i.split(",")))
	y.append(stabs[i])
matplotlib.pyplot.plot(x,y,'o')#,ls='--')
matplotlib.pyplot.ylabel("Stability")
matplotlib.pyplot.xlabel("Attributes Card.")
pylab.show()
'''
''' Attributes cardinality v/s Stability mean '''
'''
points = {}
pointsb = {}
for i in stabs:
	card = len(i.split(","))
	catd = len(lat[i])
	if card not in points:
		points[card] = []
	if catd not in pointsb:
		pointsb[catd] = []
	pointsb[catd].append(stabs[i])
	points[card].append(stabs[i])

for c in points:
	points[c] = np.mean(points[c])
for c in pointsb:
	pointsb[c] = np.mean(pointsb[c])
	
matplotlib.pyplot.semilogx(points.keys(),points.values(),'o')#,ls='--')
matplotlib.pyplot.semilogx(pointsb.keys(),pointsb.values(),'o')#,ls='--')
matplotlib.pyplot.ylabel("Stability")
matplotlib.pyplot.xlabel("Attributes Card.")
pylab.show()
'''

print mean(stabs)

# PRINTING SUMMARY
for i in levels:
	print "Cantidad de Conceptos del nivel " + str(i) + ": " + str(len(levels[i]))
